package com.huike.web.controller.system;

import com.huike.clues.domain.SysNotice;
import com.huike.clues.service.ISysNoticeService;
import com.huike.common.core.controller.BaseController;
import com.huike.common.core.domain.AjaxResult;
import com.huike.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;



@Api(tags = "通知相关接口")
@Slf4j
@RestController
@RequestMapping("/system/notice")
public class SysNoticeController extends BaseController {

    @Autowired
    private ISysNoticeService iSysNoticeService;


    /**
     * 获取系统提醒下拉列表
     *
     * @param status
     * @return
     */
    @GetMapping("/list/{status}")
    @ApiOperation("获取系统提醒下拉列表")
    public AjaxResult list(@PathVariable("status") String status) {
        SysNotice sysNotice = new SysNotice();
        sysNotice.setStatus(status);
        List<SysNotice> list = iSysNoticeService.list(sysNotice);
        return AjaxResult.success(list);
    }

    @GetMapping("/pagelist/{status}")
    @ApiOperation("分页查询")
    public TableDataInfo page(@PathVariable("status")String status) {
        startPage();
        List<SysNotice> list = iSysNoticeService.noticeList(status);
        return getDataTable(list);
    }

    @GetMapping("/{noticeId}")
    @ApiOperation("获取详细信息")
    public AjaxResult details(@PathVariable("noticeId") Integer noticeId) {
        SysNotice sysNotice = iSysNoticeService.details(noticeId);
        if (sysNotice != null) {
            return AjaxResult.success(sysNotice);
        } else {
            return AjaxResult.error(HttpStatus.NOT_FOUND.value(), "公告不存在");
        }
    }

    @PutMapping("/{noticeId}")
    @ApiOperation("未读变已读")
    public ResponseEntity<?> markAsRead(@PathVariable("noticeId") Integer noticeId) {
        if (noticeId == null) {
            return ResponseEntity.badRequest().build();
        }
        iSysNoticeService.markAsRead(noticeId);
        return ResponseEntity.ok().build();
    }
}







